package com.flash.javamate;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;

/**
 * @author sunyiming
 * @date 2018/7/27
 */
public class DigestDemo {

    private final static String COOKIE_ENCODE_KEY = "@#$fde!23^&%";

    public static void main(String[] args) {
        String username = "zxy";
        String validTime = System.currentTimeMillis() + 2000000 + "";
        String sessionId = "1df7iykunaqs61c69uuhoysxw4";
        String encodeMd5 = DigestUtils.md5Hex(username + validTime + COOKIE_ENCODE_KEY + sessionId);

        String ticket = String.format("%s:%s:%s:%s", username, validTime, sessionId, encodeMd5);
        byte[] encodeTicketByte = Base64.encodeBase64(ticket.getBytes());
        String encodeTicket = new String(encodeTicketByte);

        System.out.println(encodeTicket);


    }


}
